package cn.com.oceansoft.modules.querys.controller;

import cn.com.oceansoft.application.common.util.HttpClientUtil;
import cn.com.oceansoft.application.constant.ConfigInfo;
import cn.com.oceansoft.framework.kits.ApiResult;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;

/**
 * Created by zhangxh on 2016/10/3.
 */
@Controller
@RequestMapping("querys")
public class QueryCenterController {
    @Resource
    protected ConfigInfo configInfo;
    @RequestMapping("center")
    public String index(){
        return "querys/query_center";
    }
    @RequestMapping(value = "names", method = GET)
    public String gotorename(HttpServletRequest request) {
        return "querys/renameQuery";
    }
    @RequestMapping(value = "countnames", method = POST)
    @ResponseBody
    public ApiResult names(@RequestParam String name, HttpServletRequest request) {
        String result= HttpClientUtil.doGet(configInfo.getMsHostUrl() + "/querys/names?name="+name);
        ApiResult apiResult = JSONObject.parseObject(result, ApiResult.class);
        return apiResult;
    }
}
